package com.itheima.thymeleaf.controller;

import com.itheima.thymeleaf.model.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.*;

@Controller
@RequestMapping("/test")
public class TestController {
    @RequestMapping("/hello")
    public String hello(Model model,String id){
        //user集合
        List<User> userList=new ArrayList<>();
        userList.add(new User(1,"张三","深圳"));
        userList.add(new User(2,"里斯","北京"));
        userList.add(new User(3,"王五","上海"));


        System.out.println(id);


        model.addAttribute("users",userList);
        model.addAttribute("hello","hello welcome");

        Map<String,Object> dataMap=new HashMap<>();
        dataMap.put("no",123);
        dataMap.put("address","深圳");
        model.addAttribute("dataMap",dataMap);

        //存储一个数组
        String[] names = {"张三","李四","王五"};
        model.addAttribute("names",names);

        //储存一个日期
        model.addAttribute("now",new Date());

        //if条件
        model.addAttribute("age",22);

        return "demo";

    }
}
